home *** CD-ROM | disk | FTP | other *** search
/ Merciful 2 / Merciful - Disc 2.iso / software / h / hispeedv6.3reg.lha / HiSpeed / arexx / Label.rexx < prev    next >
OS/2 REXX Batch file  |  1993-05-27  |  7KB  |  258 lines

  1. /* Prints (disk-)labels; done on suggestion of François Helsen.    */
  2. /* The label carrier is supposed to look like this:                */
  3. /*                                                                 */
  4. /*        middle platen of DeskJet                                 */
  5. /*                ----                                             */
  6. /*             ^  !  !  ^                                          */
  7. /*             |  ----  |                                          */
  8. /*          ----------------  ------------------------             */
  9. /*          |              |       ^ offset         ^              */
  10. /*          |O            O|       !                !              */
  11. /*          |  ----------  |  ---------------       !              */
  12. /*          |O |        | O|    ^          ^        !              */
  13. /*          |  | label  |  |    ! height   !        !              */
  14. /*          |O |   1    | O|    !          ! feed   !              */
  15. /*          |  ----------  |  ----         !        !              */
  16. /*          |O            O|               !        !              */
  17. /*          |  ----------  |  ---------------       !              */
  18. /*          |O |        | O|                        ! paper        */
  19. /*          |  | label  |  |                        !              */
  20. /*          |O |   2    | O|                        !              */
  21. /*          |  ----------  |                        !              */
  22. /*          |O            O|                        !              */
  23. /*          |              |                        !              */
  24. /*          |O !        !  .                        !              */
  25. /*          |  !<------>!  .                        !              */
  26. /*          .  ! width  !  .                        !              */
  27. /*          .              |                        !              */
  28. /*          |              |                                       */
  29. /*          ----------------  ------------------------             */
  30.  
  31. /* ----------------------------------------------------------------*/
  32.  
  33. labels = 8     /* number of labels on carrier (max. 8)             */
  34. width  = 60    /* width of a label [mm]                            */
  35. height = 32    /* printable area (slighty below label height)      */
  36. feed   = 38    /* distance between two labels [mm]                 */
  37. offset = 5     /* top border (must be at least 5 mm)               */
  38. paper  = 315   /* paper height [mm]                                */
  39.  
  40. /* ----------------------------------------------------------------*/
  41.  
  42. options results
  43. shell
  44.  
  45. address HISPEED.1
  46.  
  47. SET PAPERY paper
  48. SET PAPERX 210
  49.  
  50. SET SEPARATE OFF
  51.  
  52. SET LAYOUTX 2
  53. SET LAYOUTY labels
  54.  
  55. SET HEADER  OFF        /* 5 mm still remain unusable :-( */
  56. SET QUALITY BOLD
  57.  
  58. SET TOP    offset
  59. SET BOTTOM 297 - offset - (labels - 1) * feed - height
  60.  
  61. SET DX     2
  62. SET DY     (feed - height)
  63.  
  64. /* consider position of DeskJet's middle platen (used as guide): */
  65.  
  66. SET LEFT   (210 - width) / 2 + 5
  67. SET RIGHT  (210 - width) / 2 - 5
  68.  
  69. QUERY BLOCKX           /* maximum entry length [characters]          */
  70.  
  71. columns = trunc(RESULT) - 1
  72.  
  73. if (columns < 28) then do
  74.  
  75.   SET WARN " You should select a smaller font ;-)"
  76.  
  77. end
  78.  
  79. say ""
  80. say " This Rexx-script does support printing on (disk-) labels."
  81. say " Have a look at the code if you want to adjust it to your "
  82. say " labels' dimensions (default: 69x36 mm). Use the DeskJet's"
  83. say " middle platen as guide."
  84. say ""
  85. say " Tell me the number of the 1st label you want to print or "
  86. say " 0 to exit (the sheet's top label is considered to be 1): "
  87.  
  88. pull first
  89.  
  90. if (first < 1) | (first > labels) then do
  91.  
  92.   say " Done (please close window)."
  93.   exit
  94.  
  95. end
  96.  
  97. say ""
  98. say " I'm going to ask you for directories to scan. File- and  "
  99. say " directory names will be used as label text (except system"
  100. say " directories as 'FONTS' or icon files) ..."
  101.  
  102. QUERY BLOCKY           /* how many lines can be printed on a label ? */
  103. lines = RESULT
  104.  
  105. maxEntries = lines * 2 /* max. number of entries/label (2 columns)   */
  106.  
  107.  
  108. /* remove 'waste' of last run (if any) */
  109.  
  110. shell
  111. DELETE ">NIL:" "T:LABELTEXT"
  112. address HISPEED.1
  113.  
  114. /* open 'label' file (will become output file) */
  115.  
  116. R = open('txt', "T:LABELTEXT", 'WRITE')
  117.  
  118. if (R = 0) then do
  119.   SET WARN "Error - couldn't create temporary file"
  120.   exit
  121. end
  122.  
  123. /* 'jump' to first label */
  124.  
  125. if (first > 1) then do
  126.   do piece = 0 to (first - 2)
  127.     do n = 1 to maxEntries
  128.         R = writeln('txt', "")
  129.     end
  130.   end
  131. end
  132.  
  133. /* Read directory. The original OS2.04 'list' command _must_ be  */
  134. /* available since we depend on the layout !                     */
  135.  
  136. piece     = first - 1  /* count used labels   */
  137. terminate = 0          /* user-interrupt flag */
  138.  
  139. do while (terminate = 0) & (piece < labels)
  140.  
  141.   say ""
  142.   say " PREPARE LABEL Nº" (piece + 1) ":"
  143.   say " Enter path to scan (e.g. DF0:) or <CR> to terminate."
  144.  
  145.   pull path
  146.  
  147.   if path = "" then
  148.  
  149.     terminate = 1
  150.  
  151.   else do
  152.  
  153.     /* Create directory list (last line/first line have to be ignored */
  154.  
  155.     say " scanning " path "..."
  156.  
  157.     shell
  158.     LIST path "TO" "T:TEMP"
  159.  
  160.     /* Read list & count lines */
  161.  
  162.     address HISPEED.1
  163.  
  164.     R = open('ls', "T:TEMP", 'READ')
  165.  
  166.     entries = 0
  167.  
  168.     void = readln('ls')    /* ignore header line */
  169.  
  170.     do until EOF('ls') | (entries > maxEntries)
  171.  
  172.       iodata = readln('ls')
  173.       iodata = upper(iodata)
  174.  
  175.       parse var iodata name type rest
  176.  
  177.       if ~EOF('ls') then
  178.         if right(name, 5) ~= ".INFO" then
  179.           if name ~= "S" then
  180.             if name ~= "DEVS" then
  181.               if name ~= "L" then
  182.                 if name ~= "LIBS" then
  183.                   if name ~= "FONTS" then
  184.                      if name ~= "T" then
  185.                       if name ~= "ENV" then
  186.                         if name ~= "C" then do
  187.                           if type = "DIR" then
  188.                             entry.entries = left(name, columns - 3) || " []"
  189.                           else
  190.                             entry.entries = left(name, columns)
  191.                           entries = entries + 1
  192.                         end
  193.     end
  194.  
  195.     R = close('ls')
  196.  
  197.     /* create the next label (i.e. write detected file names to output file) */
  198.  
  199.     if (entries > maxEntries) then
  200.       do
  201.         say ""
  202.         say " Sorry, too many files/directories. Some of them won't"
  203.         say " get printed (maximum is " maxEntries ")."
  204.       end
  205.     else
  206.       say " "entries " entries detected (maximum is " maxEntries ")"
  207.  
  208.     do n = 1 to maxEntries
  209.  
  210.       if n < entries then
  211.         do
  212.           index = n - 1
  213.           R = writeln('txt', entry.index)
  214.         end
  215.       else
  216.           R = writeln('txt', "")
  217.     end
  218.  
  219.     if (entries = 0) then
  220.       do
  221.         say ""
  222.         say " No files found. Please have another try ..."
  223.       end
  224.     else
  225.       piece = piece + 1
  226.  
  227.   end
  228.  
  229. end
  230.  
  231. R = close('txt')
  232.  
  233. CLR
  234. SET FILE "T:LABELTEXT"
  235.  
  236. /* anything to print ? */
  237.  
  238. QUERY JOBS
  239.  
  240. if RESULT = 0 then
  241.  
  242.   SET WARN " Couldn't set files. Maybe empty ?!"
  243.  
  244. else do
  245.  
  246.   SET ASK " Proceed with printing (Y/N) ?"
  247.   if RESULT = 1 then
  248.       PRINT
  249. end
  250.  
  251. /* clean up ...  */
  252.  
  253. shell
  254. DELETE ">NIL:" "T:TEMP"
  255.  
  256. say " Ready (please close window)."
  257.  
  258.